/*
 * @Author: your name
 * @Date: 2021-09-08 11:01:33
 * @LastEditTime: 2021-11-09 18:05:28
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \shanzhong-be\lib\utils\readFIle.js
 */
// 读取本地文件
const fs = require('fs');
const XLSX = require('xlsx');
const readLocalFile = async(url) => {
  return new Promise((resolve, reject) => {
    fs.readFile(url, function(err, data) {
      if(err){
        reject(err);
        return;
      }
      resolve(data);
    });
  });
};


// 获取文件数据
const getFileData = async() => {
  readLocalFile('../static/kongxiang.xlsx').then(res => {
    const workbook = XLSX.read(res.toString('base64'), { type: 'binary'});
    console.log(workbook,' workboolk');
    const name = workbook.SheetNames[0];
    console.log(name, ';name');
    console.log(workbook.Sheets[`${name}`]);
    const data = XLSX.utils.sheet_to_json(workbook.Sheets[`${name}`]);
    console.log(data);
  });
};

getFileData();
